2 Problem: 10081 - Tight words
3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
28 #define D(x) cout << #x " is " << x << endl
34 for (int k
, n
; scanf("%d %d", &k
, &n
)==2; ){
36 for (int last
=0; last
<=9; ++last
) dp
[1][last
] = 1.0/(k
+1);
38 for (int len
=2; len
<=n
; ++len
){
39 for (int last
=0; last
<=k
; ++last
){
40 dp
[len
][last
] = dp
[len
-1][last
];
41 if (last
> 0) dp
[len
][last
] += dp
[len
-1][last
-1];
42 if (last
< k
) dp
[len
][last
] += dp
[len
-1][last
+1];
48 for (int last
=0; last
<=k
; ++last
) ans
+= dp
[n
][last
];
49 printf("%.5lf\n", 100.0 * ans
);